<template>
  <div class='car-type-container'
       v-if="visible">
    <el-dialog title="车辆类型列表"
               :visible.sync="visible">
      <el-row>
        <el-col :span="4">
          <el-button type="primary">新增</el-button>
        </el-col>
      </el-row>

    </el-dialog>
  </div>
</template>
<script>
import { CarListApi } from '@/services/WorkCenter'
export default {
  data () {
    return {
      carTypeList: [],
      visible: false
    }
  },
  props: {
    dialogVisible: Boolean
  },
  methods: {
    dialogClose () {
      this.$emit('update:dialogVisible', false)
    },
    // 获取车辆类型
    getCarType () {
      CarListApi.getCarType({
        params: {
          page: 1
        }
      }).then(res => {
        console.log(res, 'get car type')
        let data = res.data
        if (data.data) {
          this.carTypeList = data.data
          window.localStorage.setItem('carTypeList', JSON.stringify(this.carTypeList))
        }
      }, err => {
        console.log(err)
      })
    }
  },
  watch: {
    dialogVisible (newval, oldval) {
      this.visible = newval
    }
  },
  created () {
    let localTypeList = localStorage.getItem('carTypeList')
    if (localTypeList) {
      this.carTypeList = JSON.parse(localTypeList)
    } else {
      this.getCarType()
    }
  },
  mounted () {
  }
}
</script>
<style scoped lang='scss'>
.car-type-container {
}
</style>
